package 实践.class_08.Demo_01;

abstract class GeometricObject {
    //颜色
    private String color;
    //是否填充颜色
    private boolean filled;
    //构造器
    public GeometricObject() {
        this.color = "white";
        this.filled = false;
    }

    public GeometricObject(String color, boolean flilled) {
        this.color = color;
        this.filled = flilled;
    }

    /**
     * 获取
     * @return color
     */
    public String getColor() {
        return color;
    }

    /**
     * 设置
     * @param color
     */
    public void setColor(String color) {
        this.color = color;
    }

    /**
     * 获取
     * @return flilled
     */
    public boolean isFlilled() {
        return filled;
    }

    /**
     * 设置
     * @param flilled
     */
    public void setFlilled(boolean flilled) {
        this.filled = flilled;
    }

    @Override
    public String toString() {
        return "Color: " + color + " and filled: " + filled;
    }
    //抽象方法
    //面积
    public abstract double getArea();
    //周长
    public abstract double getPerimeter();
}
class Circle extends GeometricObject{
    //半径
    private double radius;
    //构造器
    public Circle() {
        this.radius = 1;
    }

    public Circle(String color,boolean filled,double radius) {
        super(color, filled);
        this.radius = radius;
    }



    /**
     * 获取
     * @return radius
     */
    public double getRadius() {
        return radius;
    }

    /**
     * 设置
     * @param radius
     */
    public void setRadius(double radius) {
        this.radius = radius;
    }



    @Override
    //面积
    public double getArea() {
        return Math.PI * radius * radius;
    }

    @Override
    //周长
    public double getPerimeter() {
        return Math.PI * 2 * radius;
    }

    @Override
    //重写父类的toString方法
    public String toString() {
        return "Circle:\n" +
                "radius = " + radius + "\n" +
                super.toString();
    }

}
class Triangle extends GeometricObject {
    private double side1;
    private double side2;
    private double side3;

    public Triangle() {
        this.side1 = 1.0;
        this.side2 = 1.0;
        this.side3 = 1.0;
    }

    public Triangle(double side1, double side2, double side3) {
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }

    public Triangle(String color, boolean filled, double side1, double side2, double side3) {
        super(color, filled);
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }

    /**
     * 获取
     * @return side1
     */
    public double getSide1() {
        return side1;
    }

    /**
     * 设置
     * @param side1
     */
    public void setSide1(double side1) {
        this.side1 = side1;
    }

    /**
     * 获取
     * @return side2
     */
    public double getSide2() {
        return side2;
    }

    /**
     * 设置
     * @param side2
     */
    public void setSide2(double side2) {
        this.side2 = side2;
    }

    /**
     * 获取
     * @return side3
     */
    public double getSide3() {
        return side3;
    }

    /**
     * 设置
     * @param side3
     */
    public void setSide3(double side3) {
        this.side3 = side3;
    }


    @Override
    //面积
    public double getArea() {
        double s = getPerimeter() / 2;
        return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
    }

    @Override
    //周长
    public double getPerimeter() {
        return side1 + side2 + side3;
    }


    @Override
    public String toString() {
        return "Triangle:\n" +
                "side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3 + "\n" +
                super.toString();
    }
}
